#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

int n;
int w, u, v;
int ans = 0x3f3f3f;

struct treenode
{
    int weight;
    int l, r;
    int fa;
    treenode(){
        weight=l=r=0;
        fa=-1;
    }
    void setwlr(int weight=0, int l=0, int r=0)
    {
        this->weight = weight;
        this->l = l;
        this->r = r;
    }
    void setfa(int fa)
    {
        this->fa = fa;
    }
} nn[110];

bool vis[110];

void search(int i, int depth)
{
    vis[i] = true;
    treenode temp = nn[i];
    ans += temp.weight * depth;
    if (temp.l != 0 && !vis[temp.l])
        search(temp.l, depth + 1);
    if (temp.r != 0 && !vis[temp.r])
        search(temp.r, depth+1);
    if(temp.fa!=-1 && !vis[temp.fa])
        search(temp.fa, depth+1);
}

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> w >> u >> v;
        nn[i].setwlr(w, u, v);
        nn[u].setfa(i);
        nn[v].setfa(i);
    }
    for(int i=1;i<=n;i++){
        int temp =ans;
        memset(vis, false, sizeof(vis));
        ans = 0;
        search(i, 0);
        ans = min(ans, temp);
    }
    cout << ans << endl;
    //system("pause");
    return 0;
}

